﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace SpEasyServer
{
    public class Settings
    {
        private XmlDocument XmlSettings;
        public Settings(String settingsFilePath)
        {
            if (!File.Exists(settingsFilePath))
            {
                throw new FileNotFoundException("File " + settingsFilePath + " was not found!");
            }

            XmlSettings = new XmlDocument();
            XmlSettings.Load(settingsFilePath);
        }

        public String this[String key]
        {
            get
            {
                XmlNodeList nodes = XmlSettings.GetElementsByTagName(key);
                if (nodes.Count == 0)
                    return null;

                return nodes[0].FirstChild.Value;
            }
        }

        public Int32 GetInt32(String key)
        {
            String str = this[key];

            if (str == null)
                return 0;

            return Convert.ToInt32(str);
        }
    }
}
